package net.fei.scan.quick.ui

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.DisplayMetrics
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import net.fei.scan.quick.MainActivity
import net.fei.scan.quick.R

class StartActivity : AppCompatActivity() {
    private lateinit var layout: ConstraintLayout

    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_start)
        layout = findViewById(R.id.layout_start)
        calculateWidth(layout)
        Handler(Looper.myLooper()!!).postDelayed({
            jumpInterface()
        }, 2000)
    }

    private fun calculateWidth(view: View) {
        val displayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getMetrics(displayMetrics)
        val screenWidth = displayMetrics.widthPixels
        val layoutWidth = (screenWidth * 0.7).toInt()
        val layoutParams = view.layoutParams as ConstraintLayout.LayoutParams
        layoutParams.width = layoutWidth
        layoutParams.height = layoutWidth
        view.layoutParams = layoutParams
    }

    private fun jumpInterface() {
        startActivity(Intent(this@StartActivity, MainActivity::class.java))
        finish()

    }

}